//
//  XXNetWorking.swift
//  Example
//
//  Created by xx on 2025/5/29.
//

import UIKit
import FastSwiftSDK

class XXNetWorking: NSObject {
    public static let shared = XXNetWorking()
    
    let baseUrl = "http://192.168.4.1"
    
    // 前进
    func boatForward(_ callBack:@escaping FastIntBlock){
        FastNetWorking.shared.get("\(baseUrl)/drive?cmd=forward") { str in
            if str.contains("成功"){
//                FastHUD.showSuc("成功")
                callBack(1)
            }else{
                FastHUD.showErr("指令错误")
                callBack(0)
            }
        } fai: { str in
            FastHUD.showErr("发送失败")
            callBack(0)
        }
    }
    
    // 左
    func boatLeft(_ callBack:@escaping FastIntBlock){
        FastNetWorking.shared.get("\(baseUrl)/drive?cmd=left") { str in
            if str.contains("成功"){
//                FastHUD.showSuc("成功")
                callBack(1)
            }else{
                FastHUD.showErr("指令错误")
                callBack(0)
            }
        } fai: { str in
            FastHUD.showErr("发送失败")
            callBack(0)
        }
    }
    
    // 右
    func boatRight(_ callBack:@escaping FastIntBlock){
        FastNetWorking.shared.get("\(baseUrl)/drive?cmd=right") { str in
            if str.contains("成功"){
//                FastHUD.showSuc("成功")
                callBack(1)
            }else{
                FastHUD.showErr("指令错误")
                callBack(0)
            }
        } fai: { str in
            FastHUD.showErr("发送失败")
            callBack(0)
        }
    }
    
    // 停止
    func boatStop(_ callBack:@escaping FastIntBlock){
        FastNetWorking.shared.get("\(baseUrl)/drive?cmd=stop") { str in
            if str.contains("成功"){
//                FastHUD.showSuc("成功")
                callBack(1)
            }else{
                FastHUD.showErr("指令错误")
                callBack(0)
            }
        } fai: { str in
            FastHUD.showErr("发送失败")
            callBack(0)
        }
    }
    
    // 大炮转向
    func boatBigGunAngle(angle:Int,_ callBack:@escaping FastIntBlock){
        FastNetWorking.shared.get("\(baseUrl)/bigGunTurn?cmd=\(angle)") { str in
            if str.contains("成功"){
//                FastHUD.showSuc("成功")
                callBack(1)
            }else{
                FastHUD.showErr("指令错误")
                callBack(0)
            }
        } fai: { str in
            FastHUD.showErr("发送失败")
            callBack(0)
        }
    }
    
    // 大炮发射
    func boatBigGunFire(type:Bool,_ callBack:@escaping FastIntBlock){
        var cmd = "off"
        if type{
            cmd = "on"
        }
        FastNetWorking.shared.get("\(baseUrl)/bigGun?cmd=\(cmd)") { str in
            if str.contains("成功"){
//                FastHUD.showSuc("成功")
                callBack(1)
            }else{
                FastHUD.showErr("指令错误")
            }
        } fai: { str in
            FastHUD.showErr("发送失败")
        }
    }
    
    // 雷达测距
    func boatRadar(angle:Int,_ callBack:@escaping FastStrBlock){
        FastNetWorking.shared.get("\(baseUrl)/radar?cmd=\(angle)") { str in
            if str.contains("成功"){
//                FastHUD.showSuc("成功")
                callBack(str)
            }else{
                FastHUD.showErr("指令错误")
            }
        } fai: { str in
            FastHUD.showErr("发送失败")
        }
    }
    

}
